#1.创建ES对象
from elasticsearch import Elasticsearch

es = Elasticsearch(hosts='up01:9200')

#2.对ES进行操作
#2.1 新增索引库
# res = es.create(index='test01',id='1001',document={"name":"杨过","age":"18","address":"活死人墓"})
#print(res)
# res = es.index(index='test01',document={"name":"小龙女","age":"20","address":"活死人墓"})

# res = es.index(index='test01',document={"name":"小龙女","age":"20","address":"活死人墓"})
# print(res)

#2.2 修改操作
# res = es.update(index='test01',id='1001',body={"doc":{"age":"28"}})
# print(res)

#2.3 查询操作
#不加参数，检索所有的数据
#res = es.search()
#如何检索一条数据呢？
# res = es.search(index='test01',body={"query":{"ids":{"values":['1001']}}})
# print(res)

#2.4 删除操作
res = es.delete(index='test01',id='1001')
print(res)

#3.关闭ES对象
es.close()
